import { Component } from "@angular/core";
import { NavigationEnd, NavigationError, RouteConfigLoadStart, Router } from "@angular/router";

@Component({
	selector: 'app-base-router-progress-bar',
  templateUrl: './router-progress-bar.component.html',
	styleUrls: ['./router-progress-bar.component.less'],
})
export class BaseRouterProgressBarComponent {
	isFetching = false;

  constructor(
    router: Router
  ) {
    router.events.subscribe(evt => {
      if (!this.isFetching && evt instanceof RouteConfigLoadStart) {
        this.isFetching = true;
				
      }
      if (evt instanceof NavigationError) {
        this.isFetching = false;
      }
      if (!(evt instanceof NavigationEnd)) {
        return;
      }
      setTimeout(() => {
        this.isFetching = false;
      }, 100);
    });
  }
}